package fr.asip.cps3.exemple.modele.exceptions;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * Classe abstraite d'exception applicative du programme d'exemple
 */
public abstract class ExceptionProgrammeExemple extends Exception {
	
	public static final int TYPE_TRAITEMENT_GENERAL_INFO_LIB = 1;
	public static final int TYPE_TRAITEMENT_GENERAL_INIT_LIB = 2;
	public static final int TYPE_TRAITEMENT_GENERAL_TERMIN_LIB = 3;
	public static final int TYPE_TRAITEMENT_SLOTSCARTES_ATTENTE_EVENEMENT_SLOT = 4;
	public static final int TYPE_TRAITEMENT_SLOTSCARTES_LISTE_SLOTS_TOUS = 5;
	public static final int TYPE_TRAITEMENT_SLOTSCARTES_LISTE_SLOTS_AVEC_CARTE = 6;
	public static final int TYPE_TRAITEMENT_SLOTSCARTES_INFO_SLOT = 7;
	public static final int TYPE_TRAITEMENT_SLOTSCARTES_INFO_CARTE = 8;
	public static final int TYPE_TRAITEMENT_SLOTSCARTES_LISTE_ALGO = 9;
	public static final int TYPE_TRAITEMENT_SLOTSCARTES_INFO_ALGO = 10;
	public static final int TYPE_TRAITEMENT_SLOTSCARTES_INIT_PIN = 11;
	public static final int TYPE_TRAITEMENT_SLOTSCARTES_MODIF_PIN = 12;
	public static final int TYPE_TRAITEMENT_SESSIONS_OUVRE = 13;
	public static final int TYPE_TRAITEMENT_SESSIONS_INFO = 14;
	public static final int TYPE_TRAITEMENT_SESSIONS_FERME = 15;
	public static final int TYPE_TRAITEMENT_SESSIONS_FERME_TOUTES = 16;
	public static final int TYPE_TRAITEMENT_SESSIONS_AUTHENTIFIE = 17;
	public static final int TYPE_TRAITEMENT_SESSIONS_DECONNECTE = 18;
	public static final int TYPE_TRAITEMENT_OBJETS_CREER = 19;
	public static final int TYPE_TRAITEMENT_OBJETS_COPIE = 20;
	public static final int TYPE_TRAITEMENT_OBJETS_SUPPR = 21;
	public static final int TYPE_TRAITEMENT_OBJETS_TAILLE = 22;
	public static final int TYPE_TRAITEMENT_OBJETS_AFFICHE_ATTRIBUT = 23;
	public static final int TYPE_TRAITEMENT_OBJETS_MODIF_ATTRIBUT = 24;
	public static final int TYPE_TRAITEMENT_OBJETS_RECHERCHE = 25;
	public static final int TYPE_TRAITEMENT_EMPREINTE_MESSAGE = 26;
	public static final int TYPE_TRAITEMENT_EMPREINTE_FICHIER = 27;
	public static final int TYPE_TRAITEMENT_SIGNATURES_MESSAGE = 28;
	public static final int TYPE_TRAITEMENT_SIGNATURES_FICHIER = 29;
	public static final int TYPE_TRAITEMENT_VERIFICATION_FICHIER = 30;
	public static final int TYPE_TRAITEMENT_VERIFICATION_MESSAGE = 31;
	public static final int TYPE_TRAITEMENT_GENERATIONALEATOIRE_NORMALE = 32;
	public static final int TYPE_TRAITEMENT_GENERATIONALEATOIRE_SEED = 33;
	
	public static final int TYPE_TRAITEMENT_SPECIFIQUE_INITIALISATION = 100;
	public static final int TYPE_TRAITEMENT_SPECIFIQUE_ETAT_CONNEXION_CARTE = 101;
	public static final int TYPE_TRAITEMENT_SPECIFIQUE_ASSISTANT_AUTHENTIFICATION = 102;
	public static final int TYPE_TRAITEMENT_SPECIFIQUE_AUTHENTIFICATION_CARTE = 103;
	public static final int TYPE_TRAITEMENT_SPECIFIQUE_APRES_RETRAIT_CARTE = 104;
	public static final int TYPE_TRAITEMENT_SPECIFIQUE_APRES_RETRAIT_LECTEUR = 105;
	public static final int TYPE_TRAITEMENT_SPECIFIQUE_ETAT_SAISIE_CODE_PORTEUR = 106;	
	public static final int TYPE_TRAITEMENT_SPECIFIQUE_LECTURE_OBJET = 107;
	public static final int TYPE_TRAITEMENT_SPECIFIQUE_MODIFICATION_OBJET = 108;
	public static final int TYPE_TRAITEMENT_SPECIFIQUE_RECYCLAGE = 110;	


	public static final int TYPE_OBJET_SLOT = 201;
	public static final int TYPE_OBJET_TOKEN = 202;
	public static final int TYPE_OBJET_ALGORITHME = 203;
	public static final int TYPE_OBJET_SESSION = 204;
	public static final int TYPE_OBJET_CLE = 205;
	public static final int TYPE_OBJET_OBJET = 206;
	public static final int TYPE_OBJET_CERTIFICAT = 207;
	public static final int TYPE_OBJET_CLE_PUBLIQUE = 208;
	public static final int TYPE_OBJET_CLE_PRIVE = 209;
	public static final int TYPE_OBJET_DONNEES_APPLICATIVES = 210;

	public static final int TYPE_CONTROLEUR_APPLICATION = 301;
	public static final int TYPE_CONTROLEUR_ECRAN = 302;
	public static final int TYPE_CONTROLEUR_MENU = 303;

	public static final int  TYPE_VUE_EXCEPTION_CONSTRUCTION_FENETRE = 401;
	public static final int  TYPE_VUE_EXCEPTION_CONSTRUCTION_MENU = 402;
	public static final int  TYPE_VUE_EXCEPTION_AFFICHAGE_RESULTAT = 403;
	public static final int  TYPE_VUE_EXCEPTION_AFFICHAGE_ECRAN = 404;

	public static final int  TYPE_LIBRAIRIE_EXCEPTION_CHARGEMENT_LIB_P11 = 501;
	public static final int  TYPE_LIBRAIRIE_EXCEPTION_CHARGEMENT_LIB_TS = 502;	
	
	private static final long serialVersionUID = 1666755104648976506L;

	/**
	 * Constructeur
	 */
	public ExceptionProgrammeExemple() {
		super();
	}

	/**
	 * Constructeur
	 * @param message Intitulé de l'exception
	 * @param cause Cause de l'exception
	 */
	public ExceptionProgrammeExemple(String message, Throwable cause) {
		super(message, cause);
	}

	/**
	 * Constructeur
	 * @param message Intitulé de l'exception
	 */
	public ExceptionProgrammeExemple(String message) {
		super(message);
	}

	/**
	 * Constructeur
	 * @param message Intitulé de l'exception
	 * @param cause Cause de l'exception
	 */
	public ExceptionProgrammeExemple(Throwable cause) {
		super(cause);
	}
	
	/**
	 * Détermine le type d'exception
	 * @return Le type d'exception
	 */
	public abstract String getTypeException();
		
	
	/**
	 * Convertit la stackTrace en chaîne de caractère
	 * @param L'exception
	 */
	public static String getStacktrace(Throwable t) {
		
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		t.printStackTrace(pw);
		return sw.toString();
		
	}
	
}
